{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# test QAPositions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from QUANTAXIS.QAMarket.QAPosition import QA_Position"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "pos = QA_Position(code = 'RB2001')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'code': 'RB2001',\n",
       " 'instrument_id': 'RB2001',\n",
       " 'user_id': 'quantaxis',\n",
       " 'portfolio_cookie': 'portfolio',\n",
       " 'username': 'quantaxis',\n",
       " 'position_id': '5370f87f-e89e-4279-8bae-864adbcc6611',\n",
       " 'account_cookie': 'quantaxis',\n",
       " 'frozen': {},\n",
       " 'name': None,\n",
       " 'spms_id': None,\n",
       " 'oms_id': None,\n",
       " 'market_type': 'future_cn',\n",
       " 'exchange_id': None,\n",
       " 'moneypreset': 100000,\n",
       " 'moneypresetLeft': 100000,\n",
       " 'lastupdatetime': '',\n",
       " 'volume_long_today': 0,\n",
       " 'volume_long_his': 0,\n",
       " 'volume_long': 0,\n",
       " 'volume_short_today': 0,\n",
       " 'volume_short_his': 0,\n",
       " 'volume_short': 0,\n",
       " 'volume_long_frozen_today': 0,\n",
       " 'volume_long_frozen_his': 0,\n",
       " 'volume_long_frozen': 0,\n",
       " 'volume_short_frozen_today': 0,\n",
       " 'volume_short_frozen_his': 0,\n",
       " 'volume_short_frozen': 0,\n",
       " 'margin_long': 0,\n",
       " 'margin_short': 0,\n",
       " 'margin': 0,\n",
       " 'position_price_long': 0,\n",
       " 'position_cost_long': 0,\n",
       " 'position_price_short': 0,\n",
       " 'position_cost_short': 0,\n",
       " 'open_price_long': 0,\n",
       " 'open_cost_long': 0,\n",
       " 'open_price_short': 0,\n",
       " 'open_cost_short': 0,\n",
       " 'trades': [],\n",
       " 'orders': {},\n",
       " 'last_price': 0,\n",
       " 'float_profit_long': 0,\n",
       " 'float_profit_short': 0,\n",
       " 'float_profit': 0,\n",
       " 'position_profit_long': 0,\n",
       " 'position_profit_short': 0,\n",
       " 'position_profit': 0}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pos.message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2700.0, 0)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pos.update_pos(3000, amount=1,towards=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'volume_long': 1,\n",
       " 'volume_short': 0,\n",
       " 'volume_long_frozen': 0,\n",
       " 'volume_short_frozen': 0}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pos.curpos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'code': 'RB2001',\n",
       " 'instrument_id': 'RB2001',\n",
       " 'user_id': 'quantaxis',\n",
       " 'portfolio_cookie': 'portfolio',\n",
       " 'username': 'quantaxis',\n",
       " 'position_id': '5370f87f-e89e-4279-8bae-864adbcc6611',\n",
       " 'account_cookie': 'quantaxis',\n",
       " 'frozen': {},\n",
       " 'name': None,\n",
       " 'spms_id': None,\n",
       " 'oms_id': None,\n",
       " 'market_type': 'future_cn',\n",
       " 'exchange_id': None,\n",
       " 'moneypreset': 100000,\n",
       " 'moneypresetLeft': 97300.0,\n",
       " 'lastupdatetime': '',\n",
       " 'volume_long_today': 1,\n",
       " 'volume_long_his': 0,\n",
       " 'volume_long': 1,\n",
       " 'volume_short_today': 0,\n",
       " 'volume_short_his': 0,\n",
       " 'volume_short': 0,\n",
       " 'volume_long_frozen_today': 0,\n",
       " 'volume_long_frozen_his': 0,\n",
       " 'volume_long_frozen': 0,\n",
       " 'volume_short_frozen_today': 0,\n",
       " 'volume_short_frozen_his': 0,\n",
       " 'volume_short_frozen': 0,\n",
       " 'margin_long': 2700.0,\n",
       " 'margin_short': 0,\n",
       " 'margin': 2700.0,\n",
       " 'position_price_long': 3000.0,\n",
       " 'position_cost_long': 30000.0,\n",
       " 'position_price_short': 0,\n",
       " 'position_cost_short': 0,\n",
       " 'open_price_long': 3000.0,\n",
       " 'open_cost_long': 30000.0,\n",
       " 'open_price_short': 0,\n",
       " 'open_cost_short': 0,\n",
       " 'trades': [],\n",
       " 'orders': {}}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pos.static_message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'code': 'RB2001',\n",
       " 'instrument_id': 'RB2001',\n",
       " 'user_id': 'quantaxis',\n",
       " 'portfolio_cookie': 'portfolio',\n",
       " 'username': 'quantaxis',\n",
       " 'position_id': '5370f87f-e89e-4279-8bae-864adbcc6611',\n",
       " 'account_cookie': 'quantaxis',\n",
       " 'frozen': {},\n",
       " 'name': None,\n",
       " 'spms_id': None,\n",
       " 'oms_id': None,\n",
       " 'market_type': 'future_cn',\n",
       " 'exchange_id': None,\n",
       " 'moneypreset': 100000,\n",
       " 'moneypresetLeft': 97300.0,\n",
       " 'lastupdatetime': '',\n",
       " 'volume_long_today': 1,\n",
       " 'volume_long_his': 0,\n",
       " 'volume_long': 1,\n",
       " 'volume_short_today': 0,\n",
       " 'volume_short_his': 0,\n",
       " 'volume_short': 0,\n",
       " 'volume_long_frozen_today': 0,\n",
       " 'volume_long_frozen_his': 0,\n",
       " 'volume_long_frozen': 0,\n",
       " 'volume_short_frozen_today': 0,\n",
       " 'volume_short_frozen_his': 0,\n",
       " 'volume_short_frozen': 0,\n",
       " 'margin_long': 2700.0,\n",
       " 'margin_short': 0,\n",
       " 'margin': 2700.0,\n",
       " 'position_price_long': 3000.0,\n",
       " 'position_cost_long': 30000.0,\n",
       " 'position_price_short': 0,\n",
       " 'position_cost_short': 0,\n",
       " 'open_price_long': 3000.0,\n",
       " 'open_cost_long': 30000.0,\n",
       " 'open_price_short': 0,\n",
       " 'open_cost_short': 0,\n",
       " 'trades': [],\n",
       " 'orders': {},\n",
       " 'last_price': 3000,\n",
       " 'float_profit_long': 0.0,\n",
       " 'float_profit_short': 0,\n",
       " 'float_profit': 0.0,\n",
       " 'position_profit_long': 0.0,\n",
       " 'position_profit_short': 0,\n",
       " 'position_profit': 0.0}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pos.message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "pos.on_pirce_change(3100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'code': 'RB2001',\n",
       " 'instrument_id': 'RB2001',\n",
       " 'user_id': 'quantaxis',\n",
       " 'portfolio_cookie': 'portfolio',\n",
       " 'username': 'quantaxis',\n",
       " 'position_id': '5370f87f-e89e-4279-8bae-864adbcc6611',\n",
       " 'account_cookie': 'quantaxis',\n",
       " 'frozen': {},\n",
       " 'name': None,\n",
       " 'spms_id': None,\n",
       " 'oms_id': None,\n",
       " 'market_type': 'future_cn',\n",
       " 'exchange_id': None,\n",
       " 'moneypreset': 100000,\n",
       " 'moneypresetLeft': 97300.0,\n",
       " 'lastupdatetime': '',\n",
       " 'volume_long_today': 1,\n",
       " 'volume_long_his': 0,\n",
       " 'volume_long': 1,\n",
       " 'volume_short_today': 0,\n",
       " 'volume_short_his': 0,\n",
       " 'volume_short': 0,\n",
       " 'volume_long_frozen_today': 0,\n",
       " 'volume_long_frozen_his': 0,\n",
       " 'volume_long_frozen': 0,\n",
       " 'volume_short_frozen_today': 0,\n",
       " 'volume_short_frozen_his': 0,\n",
       " 'volume_short_frozen': 0,\n",
       " 'margin_long': 2700.0,\n",
       " 'margin_short': 0,\n",
       " 'margin': 2700.0,\n",
       " 'position_price_long': 3000.0,\n",
       " 'position_cost_long': 30000.0,\n",
       " 'position_price_short': 0,\n",
       " 'position_cost_short': 0,\n",
       " 'open_price_long': 3000.0,\n",
       " 'open_cost_long': 30000.0,\n",
       " 'open_price_short': 0,\n",
       " 'open_cost_short': 0,\n",
       " 'trades': [],\n",
       " 'orders': {},\n",
       " 'last_price': 3100,\n",
       " 'float_profit_long': 1000.0,\n",
       " 'float_profit_short': 0,\n",
       " 'float_profit': 1000.0,\n",
       " 'position_profit_long': 1000.0,\n",
       " 'position_profit_short': 0,\n",
       " 'position_profit': 1000.0}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pos.message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "pos1 = QA_Position(code='000001')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'code': '000001',\n",
       " 'instrument_id': '000001',\n",
       " 'user_id': 'quantaxis',\n",
       " 'portfolio_cookie': 'portfolio',\n",
       " 'username': 'quantaxis',\n",
       " 'position_id': '9ec2d402-0119-48fd-b74d-a3b9ea494292',\n",
       " 'account_cookie': 'quantaxis',\n",
       " 'frozen': {},\n",
       " 'name': None,\n",
       " 'spms_id': None,\n",
       " 'oms_id': None,\n",
       " 'market_type': 'stock_cn',\n",
       " 'exchange_id': None,\n",
       " 'moneypreset': 100000,\n",
       " 'moneypresetLeft': 100000,\n",
       " 'lastupdatetime': '',\n",
       " 'volume_long_today': 0,\n",
       " 'volume_long_his': 0,\n",
       " 'volume_long': 0,\n",
       " 'volume_short_today': 0,\n",
       " 'volume_short_his': 0,\n",
       " 'volume_short': 0,\n",
       " 'volume_long_frozen_today': 0,\n",
       " 'volume_long_frozen_his': 0,\n",
       " 'volume_long_frozen': 0,\n",
       " 'volume_short_frozen_today': 0,\n",
       " 'volume_short_frozen_his': 0,\n",
       " 'volume_short_frozen': 0,\n",
       " 'margin_long': 0,\n",
       " 'margin_short': 0,\n",
       " 'margin': 0,\n",
       " 'position_price_long': 0,\n",
       " 'position_cost_long': 0,\n",
       " 'position_price_short': 0,\n",
       " 'position_cost_short': 0,\n",
       " 'open_price_long': 0,\n",
       " 'open_cost_long': 0,\n",
       " 'open_price_short': 0,\n",
       " 'open_cost_short': 0,\n",
       " 'trades': [],\n",
       " 'orders': {},\n",
       " 'last_price': 0,\n",
       " 'float_profit_long': 0,\n",
       " 'float_profit_short': 0,\n",
       " 'float_profit': 0,\n",
       " 'position_profit_long': 0,\n",
       " 'position_profit_short': 0,\n",
       " 'position_profit': 0}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pos1.message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "from QIFIAccount import QIFI_Account, ORDER_DIRECTION, uuid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "acc = QIFI_Account(\"x1\", \"x1\")\n",
    "acc.initial()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.static_balance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'account_cookie': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      " 'accounts': {'WithdrawQuota': 0,\n",
      "              'available': 1000000,\n",
      "              'balance': 1000000,\n",
      "              'close_profit': 0,\n",
      "              'commission': 0,\n",
      "              'currency': 'CNY',\n",
      "              'deposit': 1000000,\n",
      "              'float_profit': 0,\n",
      "              'frozen_commission': 0.0,\n",
      "              'frozen_margin': 0,\n",
      "              'frozen_premium': 0.0,\n",
      "              'margin': 0,\n",
      "              'position_profit': 0,\n",
      "              'pre_balance': 0,\n",
      "              'premium': None,\n",
      "              'risk_ratio': 0.0,\n",
      "              'static_balance': 0,\n",
      "              'user_id': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      "              'withdraw': 0},\n",
      " 'bank_password': '',\n",
      " 'bankid': 'QASIM',\n",
      " 'bankname': 'QASIMBank',\n",
      " 'banks': {'QASIM': {'bank_account': '',\n",
      "                     'fetch_amount': 0.0,\n",
      "                     'id': 'QASIM',\n",
      "                     'name': 'QASIMBank',\n",
      "                     'qry_count': 0}},\n",
      " 'broker_name': 'QUANTAXIS',\n",
      " 'capital_password': '',\n",
      " 'events': {'2019-10-08 00:11:50.005237': '转账成功 1000000'},\n",
      " 'investor_name': '',\n",
      " 'model': 'SIM',\n",
      " 'money': 1000000,\n",
      " 'orders': {},\n",
      " 'password': 'f7102499-02a1-47e7-b83f-dd43e9a5002c',\n",
      " 'ping_gap': 5,\n",
      " 'portfolio': '',\n",
      " 'positions': {},\n",
      " 'pub_host': '',\n",
      " 'settlement': {},\n",
      " 'sourceid': 'QIFI_Account',\n",
      " 'status': 200,\n",
      " 'taskid': '',\n",
      " 'trade_host': '',\n",
      " 'trades': {},\n",
      " 'trading_day': '2019-10-08',\n",
      " 'transfers': {'0': {'amount': 1000000,\n",
      "                     'currency': 'CNY',\n",
      "                     'datetime': 433241234123,\n",
      "                     'error_id': 0,\n",
      "                     'error_msg': '成功'}},\n",
      " 'updatetime': '',\n",
      " 'wsuri': 'ws://www.yutiansut.com:7988'}\n",
      "{'account_cookie': '4131b780-668d-4f74-8d15-929f0a9c9740', 'user_id': '4131b780-668d-4f74-8d15-929f0a9c9740', 'instrument_id': 'RB2001', 'towards': 2, 'exchange_id': 'SHFE', 'order_time': '2019-10-08 00:11:50.162215', 'volume': 10.0, 'price': 5000.0, 'order_id': '8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc', 'seqno': 1, 'direction': 'BUY', 'offset': 'OPEN', 'volume_orign': 10.0, 'price_type': 'LIMIT', 'limit_price': 5000.0, 'time_condition': 'GFD', 'volume_condition': 'ANY', 'insert_date_time': '2019-10-08 00:11:50.162215', 'exchange_order_id': '24a6be52-f0bf-48f3-b9e2-b8e99917adaf', 'status': 100, 'volume_left': 10.0, 'last_msg': '已报'}\n"
     ]
    }
   ],
   "source": [
    "import pprint\n",
    "pprint.pprint(acc.message)\n",
    "\n",
    "r = acc.send_order('RB2001', 10, 5000, ORDER_DIRECTION.BUY_OPEN)\n",
    "print(r)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc': {'amount': 10,\n",
       "  'coeff': 4500.0,\n",
       "  'money': 45000.0}}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.frozen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "acc.receive_deal(r['instrument_id'], 4500, r['volume'], r['towards'],\n",
    "                 acc.dtstr, order_id=r['order_id'], trade_id=str(uuid.uuid4()))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'account_cookie': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      " 'accounts': {'WithdrawQuota': 0,\n",
      "              'available': 959500.0,\n",
      "              'balance': 1000000.0,\n",
      "              'close_profit': 0,\n",
      "              'commission': 0,\n",
      "              'currency': 'CNY',\n",
      "              'deposit': 1000000,\n",
      "              'float_profit': 0.0,\n",
      "              'frozen_commission': 0.0,\n",
      "              'frozen_margin': 0,\n",
      "              'frozen_premium': 0.0,\n",
      "              'margin': 40500.0,\n",
      "              'position_profit': 0.0,\n",
      "              'pre_balance': 0,\n",
      "              'premium': None,\n",
      "              'risk_ratio': 0.04049999999999998,\n",
      "              'static_balance': 0,\n",
      "              'user_id': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      "              'withdraw': 0},\n",
      " 'bank_password': '',\n",
      " 'bankid': 'QASIM',\n",
      " 'bankname': 'QASIMBank',\n",
      " 'banks': {'QASIM': {'bank_account': '',\n",
      "                     'fetch_amount': 0.0,\n",
      "                     'id': 'QASIM',\n",
      "                     'name': 'QASIMBank',\n",
      "                     'qry_count': 0}},\n",
      " 'broker_name': 'QUANTAXIS',\n",
      " 'capital_password': '',\n",
      " 'events': {'2019-10-08 00:11:50.005237': '转账成功 1000000',\n",
      "            '2019-10-08 00:11:50.176770': '全部成交 '\n",
      "                                          '8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc'},\n",
      " 'investor_name': '',\n",
      " 'model': 'SIM',\n",
      " 'money': 959500.0,\n",
      " 'orders': {'8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc': {'account_cookie': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      "                                                     'direction': 'BUY',\n",
      "                                                     'exchange_id': 'SHFE',\n",
      "                                                     'exchange_order_id': '24a6be52-f0bf-48f3-b9e2-b8e99917adaf',\n",
      "                                                     'insert_date_time': '2019-10-08 '\n",
      "                                                                         '00:11:50.162215',\n",
      "                                                     'instrument_id': 'RB2001',\n",
      "                                                     'last_msg': '全部成交',\n",
      "                                                     'limit_price': 5000.0,\n",
      "                                                     'offset': 'OPEN',\n",
      "                                                     'order_id': '8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc',\n",
      "                                                     'order_time': '2019-10-08 '\n",
      "                                                                   '00:11:50.162215',\n",
      "                                                     'price': 5000.0,\n",
      "                                                     'price_type': 'LIMIT',\n",
      "                                                     'seqno': 1,\n",
      "                                                     'status': 300,\n",
      "                                                     'time_condition': 'GFD',\n",
      "                                                     'towards': 2,\n",
      "                                                     'user_id': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      "                                                     'volume': 10.0,\n",
      "                                                     'volume_condition': 'ANY',\n",
      "                                                     'volume_left': 0.0,\n",
      "                                                     'volume_orign': 10.0}},\n",
      " 'password': 'f7102499-02a1-47e7-b83f-dd43e9a5002c',\n",
      " 'ping_gap': 5,\n",
      " 'portfolio': '',\n",
      " 'positions': {'RB2001': {'account_cookie': 'quantaxis',\n",
      "                          'code': 'RB2001',\n",
      "                          'exchange_id': None,\n",
      "                          'float_profit': 0.0,\n",
      "                          'float_profit_long': 0.0,\n",
      "                          'float_profit_short': 0,\n",
      "                          'frozen': {},\n",
      "                          'instrument_id': 'RB2001',\n",
      "                          'last_price': 4500,\n",
      "                          'lastupdatetime': '',\n",
      "                          'margin': 40500.0,\n",
      "                          'margin_long': 40500.0,\n",
      "                          'margin_short': 0,\n",
      "                          'market_type': 'future_cn',\n",
      "                          'moneypreset': 100000,\n",
      "                          'moneypresetLeft': 59500.0,\n",
      "                          'name': None,\n",
      "                          'oms_id': None,\n",
      "                          'open_cost_long': 450000.0,\n",
      "                          'open_cost_short': 0,\n",
      "                          'open_price_long': 4500.0,\n",
      "                          'open_price_short': 0,\n",
      "                          'orders': {},\n",
      "                          'portfolio_cookie': 'portfolio',\n",
      "                          'position_cost_long': 450000.0,\n",
      "                          'position_cost_short': 0,\n",
      "                          'position_id': 'c684860b-ad41-496b-aa0f-7ff0a5a47e6e',\n",
      "                          'position_price_long': 4500.0,\n",
      "                          'position_price_short': 0,\n",
      "                          'position_profit': 0.0,\n",
      "                          'position_profit_long': 0.0,\n",
      "                          'position_profit_short': 0,\n",
      "                          'spms_id': None,\n",
      "                          'trades': [],\n",
      "                          'user_id': 'quantaxis',\n",
      "                          'username': 'quantaxis',\n",
      "                          'volume_long': 10.0,\n",
      "                          'volume_long_frozen': 0,\n",
      "                          'volume_long_frozen_his': 0,\n",
      "                          'volume_long_frozen_today': 0,\n",
      "                          'volume_long_his': 0,\n",
      "                          'volume_long_today': 10.0,\n",
      "                          'volume_short': 0,\n",
      "                          'volume_short_frozen': 0,\n",
      "                          'volume_short_frozen_his': 0,\n",
      "                          'volume_short_frozen_today': 0,\n",
      "                          'volume_short_his': 0,\n",
      "                          'volume_short_today': 0}},\n",
      " 'pub_host': '',\n",
      " 'settlement': {},\n",
      " 'sourceid': 'QIFI_Account',\n",
      " 'status': 200,\n",
      " 'taskid': '',\n",
      " 'trade_host': '',\n",
      " 'trades': {'271ccb04-174c-4cc7-b6f6-1d71e3a8fbec': {'direction': 'BUY',\n",
      "                                                     'exchange_id': 'SHFE',\n",
      "                                                     'exchange_trade_id': '271ccb04-174c-4cc7-b6f6-1d71e3a8fbec',\n",
      "                                                     'instrument_id': 'RB2001',\n",
      "                                                     'offset': 'OPEN',\n",
      "                                                     'order_id': '8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc',\n",
      "                                                     'price': 4500,\n",
      "                                                     'seqno': 2,\n",
      "                                                     'trade_date_time': '2019-10-08 '\n",
      "                                                                        '00:11:50.176770',\n",
      "                                                     'trade_id': '271ccb04-174c-4cc7-b6f6-1d71e3a8fbec',\n",
      "                                                     'user_id': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      "                                                     'volume': 10.0}},\n",
      " 'trading_day': '2019-10-08',\n",
      " 'transfers': {'0': {'amount': 1000000,\n",
      "                     'currency': 'CNY',\n",
      "                     'datetime': 433241234123,\n",
      "                     'error_id': 0,\n",
      "                     'error_msg': '成功'}},\n",
      " 'updatetime': '',\n",
      " 'wsuri': 'ws://www.yutiansut.com:7988'}\n"
     ]
    }
   ],
   "source": [
    "import pprint\n",
    "pprint.pprint(acc.message)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "sr = acc.send_order('000001',10, 12, ORDER_DIRECTION.BUY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "acc.make_deal(sr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'account_cookie': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      " 'accounts': {'WithdrawQuota': 0,\n",
      "              'available': 959380.0,\n",
      "              'balance': 1000000.0,\n",
      "              'close_profit': 0,\n",
      "              'commission': 0,\n",
      "              'currency': 'CNY',\n",
      "              'deposit': 1000000,\n",
      "              'float_profit': 0.0,\n",
      "              'frozen_commission': 0.0,\n",
      "              'frozen_margin': 0,\n",
      "              'frozen_premium': 0.0,\n",
      "              'margin': 40620.0,\n",
      "              'position_profit': 0.0,\n",
      "              'pre_balance': 0,\n",
      "              'premium': None,\n",
      "              'risk_ratio': 0.04061999999999999,\n",
      "              'static_balance': 0,\n",
      "              'user_id': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      "              'withdraw': 0},\n",
      " 'bank_password': '',\n",
      " 'bankid': 'QASIM',\n",
      " 'bankname': 'QASIMBank',\n",
      " 'banks': {'QASIM': {'bank_account': '',\n",
      "                     'fetch_amount': 0.0,\n",
      "                     'id': 'QASIM',\n",
      "                     'name': 'QASIMBank',\n",
      "                     'qry_count': 0}},\n",
      " 'broker_name': 'QUANTAXIS',\n",
      " 'capital_password': '',\n",
      " 'events': {'2019-10-08 00:11:50.005237': '转账成功 1000000',\n",
      "            '2019-10-08 00:11:50.176770': '全部成交 '\n",
      "                                          '8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc',\n",
      "            '2019-10-08 00:11:50.660207': '全部成交 '\n",
      "                                          'e106d3f8-370b-4100-80bf-139963e6cb02'},\n",
      " 'investor_name': '',\n",
      " 'model': 'SIM',\n",
      " 'money': 959380.0,\n",
      " 'orders': {'8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc': {'account_cookie': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      "                                                     'direction': 'BUY',\n",
      "                                                     'exchange_id': 'SHFE',\n",
      "                                                     'exchange_order_id': '24a6be52-f0bf-48f3-b9e2-b8e99917adaf',\n",
      "                                                     'insert_date_time': '2019-10-08 '\n",
      "                                                                         '00:11:50.162215',\n",
      "                                                     'instrument_id': 'RB2001',\n",
      "                                                     'last_msg': '全部成交',\n",
      "                                                     'limit_price': 5000.0,\n",
      "                                                     'offset': 'OPEN',\n",
      "                                                     'order_id': '8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc',\n",
      "                                                     'order_time': '2019-10-08 '\n",
      "                                                                   '00:11:50.162215',\n",
      "                                                     'price': 5000.0,\n",
      "                                                     'price_type': 'LIMIT',\n",
      "                                                     'seqno': 1,\n",
      "                                                     'status': 300,\n",
      "                                                     'time_condition': 'GFD',\n",
      "                                                     'towards': 2,\n",
      "                                                     'user_id': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      "                                                     'volume': 10.0,\n",
      "                                                     'volume_condition': 'ANY',\n",
      "                                                     'volume_left': 0.0,\n",
      "                                                     'volume_orign': 10.0},\n",
      "            'e106d3f8-370b-4100-80bf-139963e6cb02': {'account_cookie': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      "                                                     'direction': 'BUY',\n",
      "                                                     'exchange_id': None,\n",
      "                                                     'exchange_order_id': 'de5e1067-f289-4c7d-859b-cbcd39ce0e06',\n",
      "                                                     'insert_date_time': '2019-10-08 '\n",
      "                                                                         '00:11:50.653582',\n",
      "                                                     'instrument_id': '000001',\n",
      "                                                     'last_msg': '全部成交',\n",
      "                                                     'limit_price': 12.0,\n",
      "                                                     'offset': '',\n",
      "                                                     'order_id': 'e106d3f8-370b-4100-80bf-139963e6cb02',\n",
      "                                                     'order_time': '2019-10-08 '\n",
      "                                                                   '00:11:50.653582',\n",
      "                                                     'price': 12.0,\n",
      "                                                     'price_type': 'LIMIT',\n",
      "                                                     'seqno': 3,\n",
      "                                                     'status': 300,\n",
      "                                                     'time_condition': 'GFD',\n",
      "                                                     'towards': 1,\n",
      "                                                     'user_id': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      "                                                     'volume': 10.0,\n",
      "                                                     'volume_condition': 'ANY',\n",
      "                                                     'volume_left': 0.0,\n",
      "                                                     'volume_orign': 10.0}},\n",
      " 'password': 'f7102499-02a1-47e7-b83f-dd43e9a5002c',\n",
      " 'ping_gap': 5,\n",
      " 'portfolio': '',\n",
      " 'positions': {'000001': {'account_cookie': 'quantaxis',\n",
      "                          'code': '000001',\n",
      "                          'exchange_id': None,\n",
      "                          'float_profit': 0.0,\n",
      "                          'float_profit_long': 0.0,\n",
      "                          'float_profit_short': 0.0,\n",
      "                          'frozen': {},\n",
      "                          'instrument_id': '000001',\n",
      "                          'last_price': 12.0,\n",
      "                          'lastupdatetime': '',\n",
      "                          'margin': 120.0,\n",
      "                          'margin_long': 120.0,\n",
      "                          'margin_short': 0,\n",
      "                          'market_type': 'stock_cn',\n",
      "                          'moneypreset': 100000,\n",
      "                          'moneypresetLeft': 100000,\n",
      "                          'name': None,\n",
      "                          'oms_id': None,\n",
      "                          'open_cost_long': 120.0,\n",
      "                          'open_cost_short': 0,\n",
      "                          'open_price_long': 12.0,\n",
      "                          'open_price_short': 0,\n",
      "                          'orders': {},\n",
      "                          'portfolio_cookie': 'portfolio',\n",
      "                          'position_cost_long': 120.0,\n",
      "                          'position_cost_short': 0,\n",
      "                          'position_id': '2d39fba9-f436-45b9-963b-10417e219145',\n",
      "                          'position_price_long': 12.0,\n",
      "                          'position_price_short': 0,\n",
      "                          'position_profit': 0.0,\n",
      "                          'position_profit_long': 0.0,\n",
      "                          'position_profit_short': 0.0,\n",
      "                          'spms_id': None,\n",
      "                          'trades': [],\n",
      "                          'user_id': 'quantaxis',\n",
      "                          'username': 'quantaxis',\n",
      "                          'volume_long': 10.0,\n",
      "                          'volume_long_frozen': 0,\n",
      "                          'volume_long_frozen_his': 0,\n",
      "                          'volume_long_frozen_today': 0,\n",
      "                          'volume_long_his': 0,\n",
      "                          'volume_long_today': 10.0,\n",
      "                          'volume_short': 0,\n",
      "                          'volume_short_frozen': 0,\n",
      "                          'volume_short_frozen_his': 0,\n",
      "                          'volume_short_frozen_today': 0,\n",
      "                          'volume_short_his': 0,\n",
      "                          'volume_short_today': 0},\n",
      "               'RB2001': {'account_cookie': 'quantaxis',\n",
      "                          'code': 'RB2001',\n",
      "                          'exchange_id': None,\n",
      "                          'float_profit': 0.0,\n",
      "                          'float_profit_long': 0.0,\n",
      "                          'float_profit_short': 0,\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                          'frozen': {},\n",
      "                          'instrument_id': 'RB2001',\n",
      "                          'last_price': 4500,\n",
      "                          'lastupdatetime': '',\n",
      "                          'margin': 40500.0,\n",
      "                          'margin_long': 40500.0,\n",
      "                          'margin_short': 0,\n",
      "                          'market_type': 'future_cn',\n",
      "                          'moneypreset': 100000,\n",
      "                          'moneypresetLeft': 59500.0,\n",
      "                          'name': None,\n",
      "                          'oms_id': None,\n",
      "                          'open_cost_long': 450000.0,\n",
      "                          'open_cost_short': 0,\n",
      "                          'open_price_long': 4500.0,\n",
      "                          'open_price_short': 0,\n",
      "                          'orders': {},\n",
      "                          'portfolio_cookie': 'portfolio',\n",
      "                          'position_cost_long': 450000.0,\n",
      "                          'position_cost_short': 0,\n",
      "                          'position_id': 'c684860b-ad41-496b-aa0f-7ff0a5a47e6e',\n",
      "                          'position_price_long': 4500.0,\n",
      "                          'position_price_short': 0,\n",
      "                          'position_profit': 0.0,\n",
      "                          'position_profit_long': 0.0,\n",
      "                          'position_profit_short': 0,\n",
      "                          'spms_id': None,\n",
      "                          'trades': [],\n",
      "                          'user_id': 'quantaxis',\n",
      "                          'username': 'quantaxis',\n",
      "                          'volume_long': 10.0,\n",
      "                          'volume_long_frozen': 0,\n",
      "                          'volume_long_frozen_his': 0,\n",
      "                          'volume_long_frozen_today': 0,\n",
      "                          'volume_long_his': 0,\n",
      "                          'volume_long_today': 10.0,\n",
      "                          'volume_short': 0,\n",
      "                          'volume_short_frozen': 0,\n",
      "                          'volume_short_frozen_his': 0,\n",
      "                          'volume_short_frozen_today': 0,\n",
      "                          'volume_short_his': 0,\n",
      "                          'volume_short_today': 0}},\n",
      " 'pub_host': '',\n",
      " 'settlement': {},\n",
      " 'sourceid': 'QIFI_Account',\n",
      " 'status': 200,\n",
      " 'taskid': '',\n",
      " 'trade_host': '',\n",
      " 'trades': {'271ccb04-174c-4cc7-b6f6-1d71e3a8fbec': {'direction': 'BUY',\n",
      "                                                     'exchange_id': 'SHFE',\n",
      "                                                     'exchange_trade_id': '271ccb04-174c-4cc7-b6f6-1d71e3a8fbec',\n",
      "                                                     'instrument_id': 'RB2001',\n",
      "                                                     'offset': 'OPEN',\n",
      "                                                     'order_id': '8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc',\n",
      "                                                     'price': 4500,\n",
      "                                                     'seqno': 2,\n",
      "                                                     'trade_date_time': '2019-10-08 '\n",
      "                                                                        '00:11:50.176770',\n",
      "                                                     'trade_id': '271ccb04-174c-4cc7-b6f6-1d71e3a8fbec',\n",
      "                                                     'user_id': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      "                                                     'volume': 10.0},\n",
      "            'e6438f70-e0b6-4940-9201-6857b64b2647': {'direction': 'BUY',\n",
      "                                                     'exchange_id': None,\n",
      "                                                     'exchange_trade_id': 'e6438f70-e0b6-4940-9201-6857b64b2647',\n",
      "                                                     'instrument_id': '000001',\n",
      "                                                     'offset': '',\n",
      "                                                     'order_id': 'e106d3f8-370b-4100-80bf-139963e6cb02',\n",
      "                                                     'price': 12.0,\n",
      "                                                     'seqno': 4,\n",
      "                                                     'trade_date_time': '2019-10-08 '\n",
      "                                                                        '00:11:50.660207',\n",
      "                                                     'trade_id': 'e6438f70-e0b6-4940-9201-6857b64b2647',\n",
      "                                                     'user_id': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
      "                                                     'volume': 10.0}},\n",
      " 'trading_day': '2019-10-08',\n",
      " 'transfers': {'0': {'amount': 1000000,\n",
      "                     'currency': 'CNY',\n",
      "                     'datetime': 433241234123,\n",
      "                     'error_id': 0,\n",
      "                     'error_msg': '成功'}},\n",
      " 'updatetime': '',\n",
      " 'wsuri': 'ws://www.yutiansut.com:7988'}\n"
     ]
    }
   ],
   "source": [
    "pprint.pprint(acc.message)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QAPOSITION 000001 amount 10.0/0 >"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.get_position('000001')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QAPOSITION RB2001 amount 10.0/0 >"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.get_position('RB2001')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "rb = acc.get_position('RB2001')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'volume_long_today': 10.0,\n",
       " 'volume_long_his': 0,\n",
       " 'volume_long': 10.0,\n",
       " 'volume_short_today': 0,\n",
       " 'volume_short_his': 0,\n",
       " 'volume_short': 0}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rb.hold_detail"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'volume_long': 10.0, 'volume_short': 0}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rb.close_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rb.position_profit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rb.float_profit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "rb.on_pirce_change(3950)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-55000.0"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rb.position_profit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "450000.0"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rb.open_cost_long"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "40500.0"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rb.margin"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4500.0"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rb.open_price_long"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "450000.0"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rb.position_cost_long"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-55000.0"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rb.float_profit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'volume_long': 10.0, 'volume_short': 0}"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rb.close_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'volume_long': 10.0,\n",
       " 'volume_short': 0,\n",
       " 'volume_long_frozen': 0,\n",
       " 'volume_short_frozen': 0}"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rb.curpos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method QA_Position.send_order of < QAPOSITION RB2001 amount 10.0/0 >>"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rb.send_order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # 下单撤单测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock_order = acc.send_order('000002',10, 20, ORDER_DIRECTION.BUY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'account_cookie': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
       " 'user_id': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
       " 'instrument_id': '000002',\n",
       " 'towards': 1,\n",
       " 'exchange_id': None,\n",
       " 'order_time': '2019-10-08 00:11:51.671322',\n",
       " 'volume': 10.0,\n",
       " 'price': 20.0,\n",
       " 'order_id': '30c41a3b-54bc-4e37-9559-1c97e49b7c83',\n",
       " 'seqno': 5,\n",
       " 'direction': 'BUY',\n",
       " 'offset': '',\n",
       " 'volume_orign': 10.0,\n",
       " 'price_type': 'LIMIT',\n",
       " 'limit_price': 20.0,\n",
       " 'time_condition': 'GFD',\n",
       " 'volume_condition': 'ANY',\n",
       " 'insert_date_time': '2019-10-08 00:11:51.671322',\n",
       " 'exchange_order_id': '7e3f7a9d-cdc3-4bb6-ab0c-6d9005f0d3a9',\n",
       " 'status': 100,\n",
       " 'volume_left': 10.0,\n",
       " 'last_msg': '已报'}"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "959180.0"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.money"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "945000.0"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.balance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-55000.0"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.float_profit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1000000.0"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.margin + acc.available+ acc.frozen_margin"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc': {'amount': 0,\n",
       "  'coeff': 4500.0,\n",
       "  'money': 0},\n",
       " 'e106d3f8-370b-4100-80bf-139963e6cb02': {'amount': 0,\n",
       "  'coeff': 12.0,\n",
       "  'money': 0},\n",
       " '30c41a3b-54bc-4e37-9559-1c97e49b7c83': {'amount': 10,\n",
       "  'coeff': 20.0,\n",
       "  'money': 200.0}}"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.frozen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "acc.cancel_order(stock_order['order_id'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'2019-10-08 00:11:50.005237': '转账成功 1000000',\n",
       " '2019-10-08 00:11:50.176770': '全部成交 8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc',\n",
       " '2019-10-08 00:11:50.660207': '全部成交 e106d3f8-370b-4100-80bf-139963e6cb02',\n",
       " '2019-10-08 00:12:30.941267': '撤单成功 30c41a3b-54bc-4e37-9559-1c97e49b7c83'}"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.events"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.frozen_margin"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc': {'amount': 0,\n",
       "  'coeff': 4500.0,\n",
       "  'money': 0},\n",
       " 'e106d3f8-370b-4100-80bf-139963e6cb02': {'amount': 0,\n",
       "  'coeff': 12.0,\n",
       "  'money': 0},\n",
       " '30c41a3b-54bc-4e37-9559-1c97e49b7c83': {'amount': 0,\n",
       "  'coeff': 20.0,\n",
       "  'money': 0}}"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.frozen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc': {'account_cookie': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
       "  'user_id': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
       "  'instrument_id': 'RB2001',\n",
       "  'towards': 2,\n",
       "  'exchange_id': 'SHFE',\n",
       "  'order_time': '2019-10-08 00:11:50.162215',\n",
       "  'volume': 10.0,\n",
       "  'price': 5000.0,\n",
       "  'order_id': '8e7bd10d-f7b6-4b8c-a556-8f98b67f1ecc',\n",
       "  'seqno': 1,\n",
       "  'direction': 'BUY',\n",
       "  'offset': 'OPEN',\n",
       "  'volume_orign': 10.0,\n",
       "  'price_type': 'LIMIT',\n",
       "  'limit_price': 5000.0,\n",
       "  'time_condition': 'GFD',\n",
       "  'volume_condition': 'ANY',\n",
       "  'insert_date_time': '2019-10-08 00:11:50.162215',\n",
       "  'exchange_order_id': '24a6be52-f0bf-48f3-b9e2-b8e99917adaf',\n",
       "  'status': 300,\n",
       "  'volume_left': 0.0,\n",
       "  'last_msg': '全部成交'},\n",
       " 'e106d3f8-370b-4100-80bf-139963e6cb02': {'account_cookie': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
       "  'user_id': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
       "  'instrument_id': '000001',\n",
       "  'towards': 1,\n",
       "  'exchange_id': None,\n",
       "  'order_time': '2019-10-08 00:11:50.653582',\n",
       "  'volume': 10.0,\n",
       "  'price': 12.0,\n",
       "  'order_id': 'e106d3f8-370b-4100-80bf-139963e6cb02',\n",
       "  'seqno': 3,\n",
       "  'direction': 'BUY',\n",
       "  'offset': '',\n",
       "  'volume_orign': 10.0,\n",
       "  'price_type': 'LIMIT',\n",
       "  'limit_price': 12.0,\n",
       "  'time_condition': 'GFD',\n",
       "  'volume_condition': 'ANY',\n",
       "  'insert_date_time': '2019-10-08 00:11:50.653582',\n",
       "  'exchange_order_id': 'de5e1067-f289-4c7d-859b-cbcd39ce0e06',\n",
       "  'status': 300,\n",
       "  'volume_left': 0.0,\n",
       "  'last_msg': '全部成交'},\n",
       " '30c41a3b-54bc-4e37-9559-1c97e49b7c83': {'account_cookie': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
       "  'user_id': '4131b780-668d-4f74-8d15-929f0a9c9740',\n",
       "  'instrument_id': '000002',\n",
       "  'towards': 1,\n",
       "  'exchange_id': None,\n",
       "  'order_time': '2019-10-08 00:11:51.671322',\n",
       "  'volume': 10.0,\n",
       "  'price': 20.0,\n",
       "  'order_id': '30c41a3b-54bc-4e37-9559-1c97e49b7c83',\n",
       "  'seqno': 5,\n",
       "  'direction': 'BUY',\n",
       "  'offset': '',\n",
       "  'volume_orign': 10.0,\n",
       "  'price_type': 'LIMIT',\n",
       "  'limit_price': 20.0,\n",
       "  'time_condition': 'GFD',\n",
       "  'volume_condition': 'ANY',\n",
       "  'insert_date_time': '2019-10-08 00:11:51.671322',\n",
       "  'exchange_order_id': '7e3f7a9d-cdc3-4bb6-ab0c-6d9005f0d3a9',\n",
       "  'status': 500,\n",
       "  'volume_left': 0,\n",
       "  'last_msg': '已撤单'}}"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.orders"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1000000.0"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.margin + acc.available+ acc.frozen_margin"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "959380.0"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.available"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
